﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;


namespace lcmyjobs.Web.enprise
{
    public partial class ListShowUser : BasePage
    {
        int type = 0, salary = 0, edu = 0, mtime = 0, exp = 0, lan = 0, level = 0, count = 0;
        string jobs, area, trade, mtimes, major, rtime, keys;
        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
        lcmyjobs.BLL.news bn = new BLL.news();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Application["webname"] != null)
                {
                    this.Title = string.Format("单位管理中心 简历搜索  {0}", Application["webname"].ToString());
                }
                if (Session["enterprise_name"] != null)
                {
                    this.lbl_title.Text = " " + Session["enterprise_name"].ToString();
                }
                if (Session["enterprise_bid"] != null)
                {
                    if (PreviousPage != null && PreviousPage.IsCrossPagePostBack && PreviousPage.IsValid)
                    {

                        if (((RadioButton)PreviousPage.FindControl("rbtnew")).Checked) type = 2;
                        if (((RadioButton)PreviousPage.FindControl("rbtold")).Checked) type = 1;
                        jobs = ((TextBox)PreviousPage.FindControl("txtjob")).Text.Trim();
                        area = ((TextBox)PreviousPage.FindControl("txtarea")).Text.Trim();
                        trade = ((TextBox)PreviousPage.FindControl("txttrade")).Text.Trim();
                        salary = int.Parse(((DropDownList)PreviousPage.FindControl("ddlsalarym")).SelectedValue.ToString());
                        edu = int.Parse(((DropDownList)PreviousPage.FindControl("ddledu")).SelectedValue.ToString());

                        if (((RadioButton)PreviousPage.FindControl("rbtt1")).Checked) mtime = 1;
                        if (((RadioButton)PreviousPage.FindControl("rbtt2")).Checked) mtime = 2;
                        if (((RadioButton)PreviousPage.FindControl("rbtt3")).Checked) { mtime = 3; mtimes = ((TextBox)PreviousPage.FindControl("txttime")).Text.ToString(); }
                        exp = int.Parse(((DropDownList)PreviousPage.FindControl("ddlExp")).SelectedValue.ToString());
                        major = ((TextBox)PreviousPage.FindControl("txtmajor")).Text.Trim();
                        lan = int.Parse(((System.Web.UI.HtmlControls.HtmlSelect)PreviousPage.FindControl("selange")).Value.ToString());
                        level = int.Parse(((System.Web.UI.HtmlControls.HtmlSelect)PreviousPage.FindControl("selevel")).Value.ToString());
                        string t = ((DropDownList)PreviousPage.FindControl("ddlrTime")).Text.Trim();
                        DateTime dt = DateTime.Now;
                        if (t == "不限") rtime = "";
                        if (t == "近三天") rtime = dt.AddDays(-3).ToString();
                        if (t == "近一周") rtime = dt.AddDays(-7).ToString();
                        if (t == "近半月") rtime = dt.AddDays(-15).ToString();
                        if (t == "近一月") rtime = dt.AddMonths(-1).ToString();
                        if (t == "近两月") rtime = dt.AddMonths(-2).ToString();
                        if (t == "近三月") rtime = dt.AddMonths(-3).ToString();
                        keys = ((TextBox)PreviousPage.FindControl("txtKeyword")).Text.Trim();

                        lcmyjobs.Model.searchCondition sc = new Model.searchCondition();
                        sc.type = type;
                        sc.jobs = jobs;
                        sc.area = area;
                        sc.trade = trade;
                        sc.salary = salary;
                        sc.edu = edu;
                        sc.mtime = mtime;
                        sc.mtimes = mtimes;
                        sc.exp = exp;
                        sc.major = major;
                        sc.lan = lan;
                        sc.level = level;
                        sc.rtime = rtime;
                        sc.keyword = keys;
                        Session["user_sc"] = sc;
                        getdate(1, AspNetPager1.PageSize, sc);
                    }
                    else if (Session["searchCondition"] != null)
                    {
                        lcmyjobs.Model.searchCondition sc = Session["searchCondition"] as lcmyjobs.Model.searchCondition;

                        type = sc.type;
                        salary = sc.salary;
                        edu = sc.edu;
                        mtime = sc.mtime;
                        exp = sc.exp;
                        lan = sc.lan;
                        level = sc.level;
                        count = sc.count;
                        jobs = sc.jobs;
                        area = sc.area;
                        trade = sc.trade;
                        mtimes = sc.mtimes;
                        major = sc.major;
                        rtime = sc.rtime;
                        keys = sc.keyword;
                        getdate(1, AspNetPager1.PageSize, sc);

                        Session.Remove("searchCondition");
                    }
                    else
                    {
                        Response.Redirect("SearchUser.html");
                    }
                }
                else
                {
                    Maticsoft.Common.MessageBox.ShowAndRedirect(this, "请先登陆！", "EnterpriseLogin.html");
                }

            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["user_sc"] != null)
            {
                getdate(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex, (lcmyjobs.Model.searchCondition)Session["user_sc"]);
            }
        }

        protected void getdate(int start, int endindex, lcmyjobs.Model.searchCondition sc)
        {
            SqlParameter[] parameters = {			 
			 			 new SqlParameter("@job_name1", SqlDbType.NVarChar,20),
                          new SqlParameter("@job_name2", SqlDbType.NVarChar,20),
                          new SqlParameter("@job_name3", SqlDbType.NVarChar,20),
                          new SqlParameter("@types", SqlDbType.Int,4), 
                          new SqlParameter("@lowpay", SqlDbType.Int,4),
                          new SqlParameter("@highpay", SqlDbType.Int,4),
                          new SqlParameter("@edu", SqlDbType.Int,4),
                          new SqlParameter("@exp", SqlDbType.Int,4),
                           new SqlParameter("@rtime", SqlDbType.DateTime),
                         new SqlParameter("@areas1", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@areas2", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@areas3", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@trades1", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@trades2", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@trades3", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@major1", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@major2", SqlDbType.NVarChar,20), 
			 			 new SqlParameter("@major3", SqlDbType.NVarChar,20), 
			 			  new SqlParameter("@jobtime", SqlDbType.NVarChar,20), 
                           new SqlParameter("@jobtimes", SqlDbType.DateTime),//19
                           new SqlParameter("@lan", SqlDbType.Int,4), 
			 			 new SqlParameter("@level", SqlDbType.Int,4), 
			 			 new SqlParameter("@startIndex", SqlDbType.Int,4), 
			 			 new SqlParameter("@endIndex", SqlDbType.Int,4),
			 			new SqlParameter("@keyword",SqlDbType.NVarChar,20),  
			 			 new SqlParameter("@count", SqlDbType.Int,4) 
			 			 
			 			 };
            string[] a;
            if (sc.jobs != "")
            {
                a = sc.jobs.Split(',');
                if (a.Length > 0)
                    parameters[0].Value = a[0];
                if (a.Length > 1)
                    parameters[1].Value = a[1];
                if (a.Length > 2)
                    parameters[2].Value = a[2];
            }
            parameters[3].Value = type;
            int low = 0, hi = int.MaxValue;
            if (sc.salary == 1) { hi = 1001; }
            if (sc.salary == 2) { low = 1000; hi = 2001; }
            if (sc.salary == 3) { low = 2000; hi = 4001; }
            if (sc.salary == 4) { low = 4000; hi = 6001; }
            if (sc.salary == 5) { low = 6000; hi = 8001; }
            if (sc.salary == 6) { low = 8000; hi = 10001; }
            if (sc.salary == 7) { low = 10000; }
            parameters[4].Value = low;
            parameters[5].Value = hi;
            parameters[6].Value = sc.edu;
            parameters[7].Value = sc.exp;
            if (sc.rtime != "")
                parameters[8].Value = sc.rtime;
            else
                parameters[8].Value = DateTime.Now.AddYears(-1);
            if (sc.area != "")
            {
                a = sc.area.Split(',');
                if (a.Length > 0)
                    parameters[9].Value = a[0];
                if (a.Length > 1)
                    parameters[10].Value = a[1];
                if (a.Length > 2)
                    parameters[11].Value = a[2];
            }
            if (sc.trade != "")
            {
                a = sc.trade.Split(',');
                if (a.Length > 0)
                    parameters[12].Value = a[0];
                if (a.Length > 1)
                    parameters[13].Value = a[1];
                if (a.Length > 2)
                    parameters[14].Value = a[2];
            }
            if (sc.major != "")
            {
                a = sc.major.Split(',');
                if (a.Length > 0)
                    parameters[15].Value = a[0];
                if (a.Length > 1)
                    parameters[16].Value = a[1];
                if (a.Length > 2)
                    parameters[17].Value = a[2];
            }
            if (sc.mtime == 0)
                parameters[18].Value = "不限";
            else if (sc.mtime == 1)
                parameters[18].Value = "随时";
            else if (sc.mtime == 2)
                parameters[18].Value = "面谈";
            else if (sc.mtime == 3)
            {
                parameters[19].Value = sc.mtimes;
            }
            parameters[20].Value = sc.lan;
            parameters[21].Value = sc.level;
            parameters[22].Value = start;
            parameters[23].Value = endindex;
            parameters[24].Value = sc.keyword;
            parameters[25].Direction = ParameterDirection.Output;
            DataSet ds = bub.PageUserSearch(parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                AspNetPager1.RecordCount = int.Parse(parameters[25].Value.ToString());
                GridView1.DataSource = ds.Tables[0];
                GridView1.DataBind();
                this.pnl_no.Visible = false;
                this.pnl_yes.Visible = true;
            }
            else
            {
                this.pnl_no.Visible = true;
                this.pnl_yes.Visible = false;
            }


        }
    }
}